<?php
	include_once ('sgbd.php');
	include_once ('auth.php');

	$COOKIE_LIFE = 1 * 1 * 60 * 60;

	if (isset($_POST['login'])) {	// try logon
		$login = $_POST['login'];
		$passwd = md5($_POST['passwd']);
		
		setcookie('login', $login, time() + $COOKIE_LIFE);
		setcookie('passwd', $passwd, time() + $COOKIE_LIFE);
		
		header ("location: main.php");
	} else if (authenticate(false)) {
		if ($_GET['action'] == 'disconnect') {	// disconnect
			setcookie ("login", "", time()-3600);
			setcookie ("passwd", "", time()-3600);
			
			$query = "INSERT INTO LOG VALUES ('$login', NOW(), '0')";
			query ($query);
			
			header ("location: index.php");		
		} else
			header ("location: main.php");
	} else {		// INDEX
?>

<html>

<head>
	<link rel="stylesheet" href="index.css" type="text/css" />
	<title>SUNSET</title>
</head>

<body>
	<h1>CAMPING CAR AMITIE</h1>
	<h2>Bienvenue chez les boutaillas</h2>
	<p id="date">27-Jan-2010</p>

	<form method='post' action='index.php'>
		<p>Identifiant.......
			<input class="input" type='text' name='login' autofocus="autofocus" /> <br/>
			Mot de passe.
			<input class="input" type='password' name='passwd' /> 
			<input name="submit" type='submit' value='Entrer' />
		</p>

		<p>Si vous n'&ecirc;tes pas enregistr&eacute;(e),<a href='form.php'>cliquez ici</a>.  </p>
	</form>
</body>
</html>
<?php } ?>
